#include <iostream>
#include <stdio.h>
#include <vector>
#define MAXROWS 30
#define MAXCOLS 80
#define DEBUG 0

using namespace std;

char grid[MAXROWS][MAXCOLS];

struct position
{
   int x, y;
};

void printMaze()
{
   int row, col;
   int finalrow = 0;
   row = col = 0;
   while(true)
   {         
      cout<<grid[row][col];

      if(finalrow && grid[row][col] == '\n')
      {
         break;
      }
      else if(grid[row][col] == '\n')
      {
         col = 0;
         row++;
      }
      else if(grid[row][col++] == '_')
         finalrow = 1;
   }
}

int rowOK(int row)
{
   return (row >= 0) && (row < MAXROWS);
}

int colOK(int col)
{
   return (col >= 0) && (col < MAXCOLS);
}

int main()
{
   int n;
   int row, col;
   int finalrow;
   char inputchar;
   position *p;
   vector <position *> positions;
   
   scanf("%d", &n);
   
   if(DEBUG) cout<<"n = "<<n<<endl;
   
   do
      scanf("%c", &inputchar);
   while(inputchar != '\n');
   
   while(n--)
   {         
      ///read
      row = col = 0;
      finalrow = 0;         
      while(true)
      {   
         if( (EOF == scanf("%c", &inputchar)) || (finalrow && inputchar == '\n') )
         {
            grid[row][col] = '\n';
            break;
         }
         
         grid[row][col++] = inputchar;
         
         if(inputchar == '*')
         {
            p = new position;
            p->x = col-1;
            p->y = row;
         }
         else if(inputchar == '\n')
         {
            col = 0;
            row++;
         }
         if(inputchar == '_')
            finalrow = 1;
      }
      
      ///solve
      positions.clear();
      positions.push_back(p);
      while(positions.size())
      {
         p = positions.back();
         positions.pop_back();
         row = p->y;
         col = p->x;
         grid[row][col] = '#';
         if(colOK(col+1) && grid[row][col+1] == ' ')
         {
            p = new position;
            p->y = row;
            p->x = col+1;
            positions.push_back(p);
         }
         if(colOK(col-1) && grid[row][col-1] == ' ')
         {
            p = new position;
            p->y = row;
            p->x = col-1;
            positions.push_back(p);
         }
         if(rowOK(row+1) && grid[row+1][col] == ' ')
         {
            p = new position;
            p->y = row+1;
            p->x = col;
            positions.push_back(p);
         }
         if(rowOK(row-1) && grid[row-1][col] == ' ')
         {
            p = new position;
            p->y = row-1;
            p->x = col;
            positions.push_back(p);
         }
      }

      printMaze();
   } 
   
   return 0;
}
